<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="lib/layui-v2.5.6/layui/css/layui.css">
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>用户等级管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 用户中心 <span
        class="c-gray en">&gt;</span> 用户管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                                              href="javascript:location.replace(location.href);" title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div class="text-c"> 日期范围：
        <input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}' })" id="datemin"
               class="input-text Wdate" style="width:120px;">
        -
        <input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d' })" id="datemax"
               class="input-text Wdate" style="width:120px;">
        <input type="text" class="input-text" style="width:250px" placeholder="输入会员名称、电话、邮箱" id="" name="">
        <button type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜用户
        </button>
    </div>
    <div class="mt-20">
        <table id="member-level-list" lay-filter="member-level-list-filter"></table>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="lib/layui-v2.5.6/layui/layui.js"></script>
<script type="text/html" id="tool">
    <div class="layuibtn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
        <button class="layui-btn layui-btn-sm" lay-event="delete">删除</button>
    </div>
</script>
<script type="text/javascript">
    var tableId;
    var layer;
    var memberIds = [];
    $(document).ready(function () {
        layui.use(['table', 'layer'], function () {
            var table = layui.table;
            layer = layui.layer;
            tableId = table.render({
                elem: '#member-level-list'
                , url: '/Olala/customerLevelInfo/page' //数据接口
                , page: true //开启分页
                , toolbar: '#tool'
                , method: 'post'
                , response: {
                    statusCode: 20 //规定成功的状态码，默认：0
                }
                , cols: [
                    [ //表头
                        {field: "checkbox", title: "选择", type: "checkbox", width: "5%"},
                        {field: "customerLevelId", title: "ID", width: "5%"},
                        {field: "levelName", title: "级别名称", width: "10%"},
                        {field: "minPoint", title: "最低积分", width: "10%"},
                        {field: "maxPoint", title: "最高积分", width: "10%"},
                        {
                            field: "levelStatus", title: "状态", width: "5%",
                            templet: function (data) {
                                var msg = data.levelStatus ? '启用' : '禁用';
                                var className = data.levelStatus ? '' : ' layui-btn-danger';
                                return " <button class=\"layui-btn layui-btn-xs" + className + "\" lay-event=\"delete\" onclick='publish(" + data.customerLevelId + ")'>" + msg + "</button>";
                            }
                        },
                        {field: "modifiedTime", title: "修改时间", width: "15%"},
                        {
                            title: "操作", width: "10%",
                            templet: function (data) {
                                return " <button class=\"layui-btn layui-btn-sm\" onclick='update(" + data.customerLevelId + ")' lay-event=\"delete\">编辑</button>"
                            }
                        },
                    ]
                ]
            });

            table.on('checkbox(member-level-list-filter)', function (obj) {
                if (obj.checked) {
                    memberIds[obj.data.customerLevelId] = obj.data.customerLevelId;
                } else {
                    memberIds.splice(obj.data.customerLevelId, 1);
                }
            });

            //监听事件
            table.on('toolbar(member-level-list-filter)', function (obj) {
                switch (obj.event) {
                    case 'add':
                        add();
                        break;
                    case 'delete':
                        del();
                        break;
                }
            });

        });

    });

    function add() {
        var index = layer.open({
            type: 2,
            title: '等级添加',
            shade: 0.8,
            content: 'member-level-add.html',
            end: function () {
                tableId.reload();
            }
        });
        layer.full(index);
    }

    function del() {
        var index = layer.confirm('确认删除？', {
            btn: ['确认', '取消'], //按钮
            end: function () {
                tableId.reload();
            }
        }, function () {
            var ids = [];
            for (var i = 0; i < memberIds.length; i++) {
                if (memberIds[i]) {
                    ids.push(memberIds[i]);
                }
            }
            $.ajax({
                url: "/Olala/customerLevelInfo/delByIds",
                data: {
                    ids: ids
                },
                traditional: true,
                dataType: "json",
                type: "post",
                success: function (result) {
                    layer.msg(result.msg);
                    layer.close(index);
                }
            });
        }, function () {
            layer.close(index);
        });
    }

    function update(id) {
        localStorage.setItem("member-level-id", id);
        var index = layer.open({
            type: 2,
            title: '资讯',
            shade: 0.8,
            content: 'member-level-update.html',
            end: function () {
                tableId.reload();
                localStorage.removeItem("member-level-id");
            }
        });
        layer.full(index);
    }

    function publish(id) {
        var index = layer.confirm('修改？', {
            btn: ['启用', '禁用', '取消'], //按钮
            end: function () {
                tableId.reload();
            }
        }, function () {
            $.post("/Olala/customerLevelInfo/updateById", {customerLevelId: id, levelStatus: true}, function (result) {
                layer.msg(result.msg);
            }, 'json');
        }, function () {
            $.post("/Olala/customerLevelInfo/updateById", {customerLevelId: id, levelStatus: false}, function (result) {
                layer.msg(result.msg);
            }, 'json');
        }, function () {
            layer.close(index);
        });
    }
</script>
</body>
</html>